/**
 * Description:一些注释<br/> CreateTime:2019-03-27<br/> Creater:
 * yangpengfei@think.cn <br/>
 */
// JavaScript代码区域
layui
		.use(
				[ 'element', 'jquery' ],
				function() {
					var element = layui.element;
					var $ = layui.jquery;
					var layer = layui.layer;
					$
							.ajax({
								url : "/menu",
								type : "GET",
								dataType : "json",
								success : function(result) {
									var resetHtml = "";
									if (result != null && result != "") {
										resetHtml = "<ul class='layui-nav layui-nav-tree' lay-filter='test'>";
										for ( var i in result) {
											resetHtml += "<li class='layui-nav-item "+(i == 0 ? " layui-nav-itemed" :"")+"'>"
													+ "<a class='' href='javascript:;'>"
													+ result[i].groupName
													+ "</a>";

											if (typeof (result[i].children) != "undefined"
													&& result[i].children != null
													&& result[i].children != "") {
												resetHtml += "<dl class='layui-nav-child'>";
												var child = result[i].children;
												for ( var j in child) {
													resetHtml += "<dd>"
															+ "<a href='"
															+ child[j].pageAddress
															+ "' target = 'mainFrame' class='page-node' parent-name='"+result[i].groupName+"'>"
															+ child[j].pageName
															+ "</a>" + "</dd>";
												}
												resetHtml += "</dl>";
											}
											resetHtml += "</li>";
										}
										resetHtml += "</ul>";
									}
									$("#menuBar").html(resetHtml);
									// 重新渲染动态效果
									element.init();
								},
								error : function(e) {
									layer.msg('操作菜单获取失败，请检查服务状态', {
										icon : 5
									});
								}
							});
					$(document).on('click','.page-node',function(){
						$("#firstNode").text($(this).attr("parent-name"));
						$("#childNode").text($(this).text());
					});
				});